var uid, ws, daijiedan=0;
document.addEventListener('plusready',function(){ 
	uid = plus.storage.getItem('uid');
	ws = plus.webview.currentWebview();
	console.log(apiRoot+"?m=home&c=medicinal&a=orderList&uid="+uid+"&pati=2"); 
	$.ajax({
		type:"get",
		url :apiRoot+"?m=home&c=medicinal&a=orderList",
		data : {
			uid :uid,
			pati :2
		},
		success :function(data){ 
			plus.storage.setItem('slist',data);
			var data = $.parseJSON(data);
			plus.nativeUI.closeWaiting();
			if(data){
//				console.log(JSON.stringify(data));
				var str1 = str2 = str3 = '';
				$.each(data, function(k,v) {
//					console.log(JSON.stringify(v.uid));
					if(v.status == 1){
						daijiedan++;
					}
					switch(v.status){
						case '1':
						str1 += '<div class="mui-table-view table-view-cell bbs-ico" data-id="'+v.id+'" data-total="'+v.total+'" data-bid="'+v.uid+'">'+
								'<div class="overflow-h">'+
									'<i><img src="'+getAvatar(v.binfo.avatar)+'"/></i>'+
									'<div>'+
										'<li>'+
											'<span>'+v.binfo.name+'</span>'+
											'<span class="mui-h6 inquiry-right">待接单</span>'+
										'</li>'+
										'<li class="mui-h6 ">'+
											'<span>'+v.ztime+'</span>'+
										'</li>'+
									'</div>'+
								'</div>'+
							'</div>';
						break;
						case '2':
						str2 += '<div class="mui-table-view table-view-cell bbs-ico" data-id="'+v.id+'" data-total="'+v.total+'" data-bid="'+v.uid+'">'+
								'<div class="overflow-h">'+
									'<i><img src="'+getAvatar(v.binfo.avatar)+'"/></i>'+
									'<div>'+
										'<li>'+
											'<span>'+v.binfo.name+'</span>'+
											'<span class="mui-h6 inquiry-right">待确认</span>'+
										'</li>'+
										'<li class="mui-h6 ">'+
											'<span>'+v.ztime+'</span>'+
										'</li>'+
									'</div>'+
								'</div>'+
							'</div>';
						break;
						case '3':
						str3 += '<div class="mui-table-view table-view-cell bbs-ico" data-id="'+v.id+'" data-total="'+v.total+'" data-bid="'+v.uid+'">'+
								'<div class="overflow-h">'+
									'<i><img src="'+getAvatar(v.binfo.avatar)+'"/></i>'+
									'<div>'+
										'<li>'+
											'<span>'+v.binfo.name+'</span>'+
											'<span class="mui-h6 inquiry-right">已完成</span>'+
										'</li>'+
										'<li class="mui-h6 ">'+
											'<span>'+v.ztime+'</span>'+
										'</li>'+
									'</div>'+
								'</div>'+
							'</div>';
						break;
					}
				});
//				alert('您有'+daijiedan+'条药单等待接单');
				$('#item1').html(str1);
				$('#item2').html(str2);
				$('#item3').html(str3);
				$('.bbs-ico').click(function(){
					var id = $(this).attr('data-id');
					var total = $(this).attr('data-total');//处方费
					var bid = $(this).attr('data-bid');//病人Id
//					console.log(id+" "+total);
					goDetail(id, total, bid);
				})
			}else{
				toast('暂无订单信息！');
			}
		},
		error :function(e){
			console.log(JSON.stringify(e));
			errortoast();
		}
	})
},false)
//进入订单详情->病例（订单）Id
function goDetail(id, total, bid){
	console.log(id+" "+total+" "+bid);
	goNewPage('free-information-order-1-sj.html', {aid:id, spage:ws.id, total:total, bid:bid});
}